package com.personal.gateway.flinkAllCommand.flinkEnvironment;

import com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkTargetEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOptionBuilder;
import com.personal.gateway.flinkAllCommand.configurationOption.KeyIndexInfomationDao;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorDouble;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorListString;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorString;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.*;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckDouble;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckListString;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckString;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorDouble;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorListString;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorString;

import java.util.Arrays;
import java.util.List;

import static com.personal.gateway.custom.customEnum.flinkCommandEnum.DockerPullPolicyEnum.DOCKER_PULL_POLICY_TYPE_CLASS;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkTargetEnum.KUBERNETES_APPLICATION;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkTargetEnum.KUBERNETES_SESSION;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.K8sLoadBalancerEnum.K8S_LOAD_BALANCER_TYPE_CLASS;
import static com.personal.gateway.flinkAllCommand.FlinkExecuteCommand.ENVIRONMENT_CONFIG;

/**
 * @author BigHead
 * @date 2022/1/20 10:26
 * @description K8sEnvironment
 */
public class K8sEnvironment extends FlinkEnvironmentTypeClass {

    public final ConfigurationOption<String, ConfigurationTypeString> CLUSTER_ID = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("CLUSTER_ID", 2))
            .webShowName("集群唯一ID")
            .describe("指定K8S运行集群唯一名称")
            .typeString()
            .setExampleValue("WordCount_Cluster")
            .webObjectGenerator(WebObjectGeneratorString.class)
            .parameterCheck(ParameterCheckString.class)
            .configurationGenerator(ConfigurationGeneratorString.class)
            .build();

    public final ConfigurationOption<String, ConfigurationTypeString> DOCKER_IMAGE_NAME = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("DOCKER_IMAGE_NAME", 3))
            .webShowName("镜像名称")
            .describe("Docker的镜像名称，用作定位应用镜像")
            .typeString()
            .setExampleValue("default.WordCountImage:v1.0")
            .webObjectGenerator(WebObjectGeneratorString.class)
            .parameterCheck(ParameterCheckString.class)
            .configurationGenerator(ConfigurationGeneratorString.class)
            .build();

    public final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> PULL_POLICY = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("PULL_POLICY", 4))
            .webShowName("镜像更新策略")
            .describe("指定DockerImage的镜像的pull策略")
            .typeEnum(DOCKER_PULL_POLICY_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<List<String>, ConfigurationTypeListString> PULL_SECRETS = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("PULL_SECRETS", 5))
            .webShowName("docker密钥")
            .describe("用于访问私有映像注册表的Kubernetes秘密的分号分隔列表")
            .typeListString()
            .setExampleValue(Arrays.asList("docker-login", "WordCount_Secrets"))
            .webObjectGenerator(WebObjectGeneratorListString.class)
            .parameterCheck(ParameterCheckListString.class)
            .configurationGenerator(ConfigurationGeneratorListString.class)
            .build();

    public final ConfigurationOption<String, ConfigurationTypeString> NAME_SPACE = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("NAME_SPACE", 6))
            .webShowName("资源空间名")
            .describe("K8s的资源空间名，用作资源隔离和权限隔离")
            .typeString()
            .setExampleValue("default", "flink_namespace")
            .webObjectGenerator(WebObjectGeneratorString.class)
            .parameterCheck(ParameterCheckString.class)
            .configurationGenerator(ConfigurationGeneratorString.class)
            .build();

    public final ConfigurationOption<String, ConfigurationTypeString> SERVICE_ACCOUNT = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("SERVICE_ACCOUNT", 7))
            .webShowName("K8s账户")
            .describe("K8s的账户，同样用作权限资源隔离等")
            .typeString()
            .setExampleValue("flink-service-account")
            .webObjectGenerator(WebObjectGeneratorString.class)
            .parameterCheck(ParameterCheckString.class)
            .configurationGenerator(ConfigurationGeneratorString.class)
            .build();

    public final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> REST_SERVICE_EXPOSED_TYPE = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("REST_SERVICE_EXPOSED_TYPE", 8))
            .webShowName("服务暴漏模式")
            .describe("K8s的服务暴漏模式")
            .typeEnum(K8S_LOAD_BALANCER_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<Double, ConfigurationTypeDouble> K8S_TM_CPU = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("TM_CPU", 9))
            .webShowName("CPU个数")
            .describe("任务管理器使用的cpu个数。默认情况下，cpu设置为每个TaskManager的槽位数")
            .necessary(false)
            .typeDouble()
            .setExampleValue(1.0, 2.5)
            .webObjectGenerator(WebObjectGeneratorDouble.class)
            .parameterCheck(ParameterCheckDouble.class)
            .configurationGenerator(ConfigurationGeneratorDouble.class)
            .build();

    public final ConfigurationOption<String, ConfigurationTypeString> JAR_PATH = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("JAR_PATH", 10))
            .webShowName("JAR地址")
            .describe("包装在镜像内的执行JAR包地址")
            .typeString()
            .setExampleValue("/opt/flink/usrlib/WordCount.jar")
            .webObjectGenerator(WebObjectGeneratorString.class)
            .parameterCheck(ParameterCheckString.class)
            .configurationGenerator(ConfigurationGeneratorString.class)
            .build();


    @Override
    protected FlinkTargetEnum[] setFlinkTargetEnums() {
        return new FlinkTargetEnum[]{KUBERNETES_SESSION, KUBERNETES_APPLICATION};
    }
}
